import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:gourmet/color/hex.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/radian.dart';
import 'package:gourmet/utils/styles.dart';
import 'package:gourmet/utils/svg.dart';
import 'package:gourmet/utils/tools.dart';

class SearchOrderResultController extends GetxController {
  late TextEditingController textEditingController;

  @override
  void onInit() {
    textEditingController = ToolsUtils.editingController('华莱士');
    super.onInit();
  }

  @override
  void onClose() {
    textEditingController.dispose();
    super.onClose();
  }
}

class SearchOrderResultPage extends GetView<SearchOrderResultController> {
  const SearchOrderResultPage({super.key});

  @override
  Widget build(BuildContext context) {
    return MediaQuery.removeViewPadding(
      context: context,
      removeBottom: true,
      removeLeft: true,
      removeRight: true,
      removeTop: true,
      child: Scaffold(
        backgroundColor: HexColor(ColorsUtils.colorF7f7),
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(44 + Get.mediaQuery.padding.top),
          child: AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark,
            child: Container(
              padding: EdgeInsets.only(top: Get.mediaQuery.padding.top),
              height: 44 + Get.mediaQuery.padding.top,
              color: Colors.white,
              child: Row(
                children: [
                  GestureDetector(
                    onTap: Get.back,
                    child: Container(
                      width: 40,
                      alignment: Alignment.center,
                      child: Icon(
                        CupertinoIcons.chevron_back,
                        size: 18,
                        color: HexColor(ColorsUtils.color0000),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Center(
                      child: TextField(
                        cursorHeight: 20,
                        cursorWidth: 3,
                        cursorRadius: const Radius.circular(2),
                        cursorColor: HexColor(ColorsUtils.colorFf64),
                        controller: controller.textEditingController,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color0000),
                        decoration: InputDecoration(
                          fillColor: HexColor(ColorsUtils.colorF5f5),
                          hintText: '请输入商家或商品名称',
                          hintStyle: StylesUtils.customTextStyle(
                              color: ColorsUtils.color9999),
                          isCollapsed: true,
                          filled: true,
                          isDense: true,
                          prefixIcon: Icon(
                            CupertinoIcons.search,
                            color: ColorsUtils.parseColorFromHexString(
                                ColorsUtils.color9999),
                            size: 20.w,
                          ),
                          suffixIcon: GestureDetector(
                            onTap: () {
                              controller.textEditingController.text = '';
                            },
                            child: Icon(
                              CupertinoIcons.xmark_circle_fill,
                              size: 20.w,
                              color: HexColor(ColorsUtils.color9999),
                            ),
                          ),
                          contentPadding: const EdgeInsets.only(top: 10),
                          enabledBorder: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(17.5),
                            borderSide: BorderSide.none,
                          ),
                          focusedBorder: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(17.5),
                            borderSide: BorderSide.none,
                          ),
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(17.5),
                            borderSide: BorderSide.none,
                          ),
                          constraints: const BoxConstraints.expand(
                              width: 270, height: 35),
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {},
                    child: Container(
                      width: 60,
                      alignment: Alignment.center,
                      child: Text(
                        '搜索',
                        softWrap: true,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color0000,
                            fontSize: StylesUtils.fontSize16),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                margin: const EdgeInsets.only(top: 10),
                alignment: Alignment.center,
                child: Container(
                  constraints: const BoxConstraints(maxWidth: 345),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.r),
                  ),
                  padding:
                      const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
                  alignment: Alignment.centerLeft,
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Image.network(
                            'https://img0.baidu.com/it/u=655977884,3582260165&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
                            width: 40,
                            height: 40,
                          ),
                          Expanded(
                            child: Container(
                              padding: const EdgeInsets.only(left: 10),
                              alignment: Alignment.centerLeft,
                              child: Text.rich(
                                TextSpan(
                                  children: [
                                    TextSpan(
                                      text: '华莱士-凤凰广场2店 ',
                                      style: StylesUtils.customTextStyle(
                                          fontSize: StylesUtils.fontSize16,
                                          fontWeight: FontWeight.w700,
                                          color: ColorsUtils.color0000),
                                    ),
                                    WidgetSpan(
                                        child: Icon(
                                          Icons.arrow_forward_ios_outlined,
                                          size: 15,
                                          color: ColorsUtils
                                              .parseColorFromHexString(
                                                  ColorsUtils.color9999),
                                        ),
                                        alignment: PlaceholderAlignment.middle),
                                  ],
                                ),
                              ),
                            ),
                          ),
                          Container(
                            alignment: Alignment.centerRight,
                            child: Text(
                              '交易成功',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.colorFf64,
                                  fontSize: StylesUtils.fontSize16),
                            ),
                          ),
                        ],
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(vertical: 15),
                        child: Row(
                          children: [
                            Image.network(
                              'https://img0.baidu.com/it/u=3832533788,1331377521&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1720112400&t=708adcf9030f25978a25ccba4432226b',
                              width: 60,
                              height: 60,
                              fit: BoxFit.fill,
                            ),
                            Container(
                              margin: const EdgeInsets.only(left: 10),
                              constraints: const BoxConstraints.expand(
                                  width: 60, height: 60),
                              child: Stack(
                                clipBehavior: Clip.none,
                                children: [
                                  Image.network(
                                    'https://img1.baidu.com/it/u=76139247,1491935982&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=511',
                                    width: 60,
                                    height: 60,
                                    fit: BoxFit.fill,
                                  ),
                                  Positioned(
                                    top: -8,
                                    right: -5,
                                    child: Container(
                                      constraints: const BoxConstraints.expand(
                                          width: 15, height: 15),
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(7.5),
                                        border: Border.all(
                                          color:
                                              HexColor(ColorsUtils.colorFf64),
                                        ),
                                        color: Colors.white,
                                      ),
                                      alignment: Alignment.center,
                                      child: Text(
                                        '2',
                                        style: StylesUtils.customTextStyle(
                                            color: ColorsUtils.colorFf64,
                                            fontSize: StylesUtils.fontSize11),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Expanded(
                              child: Align(
                                alignment: Alignment.centerRight,
                                child: Text(
                                  '共3件',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color7979),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          '实付款 ￥41',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color0000,
                              fontWeight: FontWeight.w700),
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(top: 15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            SvgUtils.assetName('u4333', width: 35, height: 35),
                            Container(
                              constraints: const BoxConstraints.expand(
                                  width: 90, height: 35),
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(17.5),
                                  gradient: LinearGradient(
                                      colors: [
                                        //linear-gradient(90deg, rgba(255, 153, 0, 1) 0%, rgba(255, 153, 0, 1) 0%, rgba(254, 70, 1, 1) 100%, rgba(254, 70, 1, 1) 100%)
                                        ColorsUtils.rgba(255, 153, 0, 1),
                                        ColorsUtils.rgba(255, 153, 0, 1),
                                        ColorsUtils.rgba(254, 70, 1, 1),
                                        ColorsUtils.rgba(254, 70, 1, 1)
                                      ],
                                      stops: const [
                                        0,
                                        0,
                                        1.0,
                                        1.0
                                      ],
                                      transform: GradientRotation(
                                          RadianUtils.angleToRadian(90)),
                                      begin: Alignment.centerLeft,
                                      end: Alignment.centerRight)),
                              alignment: Alignment.center,
                              child: Text(
                                '再次购买',
                                style: StylesUtils.customTextStyle(),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
